<?php
/** @var Dingo\Api\Routing\Router $api */
$api->group([
    'version' => 'v1',
    'namespace' => 'App\Http\Controllers\Admin',
    'prefix' => 'api/admin',
], function ($api) {
    // 验证码
    $api->get('pic-captcha', 'AuthController@picCaptcha'); // 获取图片验证码
    $api->post('sms-captcha', 'AuthController@smsCaptcha'); // 获取短信验证码
    $api->post('verification-sms-captcha', 'AuthController@verificationSmsCaptcha'); // 验证短信验证码是否正确
    $api->patch('reset-password/{phone}', 'AuthController@resetPassword'); // 重置密码

    // 调试用
    $api->group(['prefix' => 'dev'], function () use ($api) {
        $api->get('restore-orders-export', ['uses' => 'DevController@exportRestoreOrders']); // 重新下单结果导出
        $api->get('fzt-payment-order-status', ['uses' => 'DevController@exportFztPaymentOrderStatus']); // 分账通订单状态导出
        $api->group(['prefix' => 'clean-cache'], function () use ($api) {
            $api->delete('activities', ['uses' => 'DevController@cleanCacheActivities']); // 清理活动列表缓存
        });
    });

    // 登录
    $api->post('auth', 'AuthController@store'); // 创建 token

    $api->group(['middleware' => 'auth:admin'], function () use ($api) {
        $api->group(['prefix' => 'index'], function () use ($api) {
            $api->get('/daily-statistics', 'IndexController@dailyStatistics'); // 首页统计
        });

        // 权限相关
        $api->group(['prefix' => 'auth'], function () use ($api) {
            $api->put('/', 'AuthController@update'); // refresh token
            $api->delete('/', 'AuthController@destory'); //  销毁 token
            $api->get('info', 'AuthController@info'); // 用户(权限)详情
        });

        // 管理员
        $api->group(['prefix' => 'managers'], function () use ($api) {
            $api->get('/', ['uses' => 'ManagerController@list']); // 列表
            $api->post('/', ['uses' => 'ManagerController@store']); // 新增
            $api->patch('/', 'ManagerController@update'); // 编辑
        });

        // 角色
        $api->group(['prefix' => 'roles'], function () use ($api) {
            $api->get('/', ['uses' => 'RoleController@list']); // 列表
            $api->post('/', ['uses' => 'RoleController@store']); // 新增
            $api->patch('/{id}', ['uses' => 'RoleController@update']); // 编辑
            $api->get('/{id}', 'RoleController@info'); // 详情
        });

        // banner
        $api->group(['prefix' => 'banners'], function () use ($api) {
            $api->get('/', 'BannerController@list'); // 列表
            $api->post('/', 'BannerController@store'); // 新增
            $api->delete('/{id}', 'BannerController@delete'); // 新增
            $api->patch('/{id}', 'BannerController@update'); // 编辑
        });

        // 快递公司
        $api->group(['prefix' => 'courier_companies'], function () use ($api) {
            $api->get('/', ['uses' => 'CourierCompanyController@list']); // 列表
            $api->post('/', ['uses' => 'CourierCompanyController@store']); // 新增
            $api->delete('/{id}', ['uses' => 'CourierCompanyController@delete']); // 删除
            $api->patch('/{id}', ['uses' => 'CourierCompanyController@update']); // 编辑
        });

        // 操作日志
        $api->get('operation-log', ['uses' => 'ActivityLogController@list']);

        // 供应商
        $api->group(['prefix' => 'suppliers'], function () use ($api) {
            $api->get('/', ['uses' => 'SupplierController@list']); // 列表
            $api->post('/', ['uses' => 'SupplierController@store']); // 新增
            $api->patch('/{id}', ['uses' => 'SupplierController@update']); // 编辑
            $api->get('/{id}', ['uses' => 'SupplierController@info']); // 详情
        });

        // 合伙人
        $api->group(['prefix' => 'partners'], function () use ($api) {
            $api->get('/', ['uses' => 'PartnerController@list']); // 列表
            $api->post('/', ['uses' => 'PartnerController@store']); // 新增
            $api->delete('/{id}', ['uses' => 'PartnerController@delete']); // 删除
            $api->patch('/{id}', ['uses' => 'PartnerController@update']); // 编辑
        });

        // 附件
        $api->group(['prefix' => 'attachments'], function () use ($api) {
            $api->get('/sts-token', 'AttachmentController@storeToken'); // 获取临时凭证
            $api->post('/', 'AttachmentController@upload'); // 上传
            $api->get('/download-async-export-task/{id}', 'AttachmentController@downloadAsyncExportTask'); // 下载异步导出内容
            $api->get('/download-async-export-task', 'AttachmentController@asyncExportTaskList'); // 异步导出操作列表
        });

        // 站内信
        $api->group(['prefix' => 'website-letter'], function () use ($api) {
            $api->get('/', ['uses' => 'WebsiteLetterController@list']); // 列表
            $api->get('/{id}', ['uses' => 'WebsiteLetterController@info']); // 详情
            $api->post('/', ['uses' => 'WebsiteLetterController@store']); // 新增
            $api->delete('/{id}', ['uses' => 'WebsiteLetterController@delete']); // 删除
            $api->patch('/{id}', ['uses' => 'WebsiteLetterController@update']); // 编辑
        });

        // 商品
        $api->group(['prefix' => 'commodities'], function () use ($api) {
            // 分类
            $api->group(['prefix' => 'categories'], function () use ($api) {
                $api->post('/', ['uses' => 'CommodityCategoryController@store']); // 新增
                $api->get('/', ['uses' => 'CommodityCategoryController@list']); // 列表
                $api->delete('/{id}', ['uses' => 'CommodityCategoryController@delete']); // 删除
                $api->patch('/{id}', ['uses' => 'CommodityCategoryController@update']); // 编辑
            });

            // 今日直播
            $api->group(['prefix' => 'live-today'], function () use ($api) {
                $api->get('/{id}', ['uses' => 'CommodityActivityController@info']); // 详情
                $api->post('/', ['uses' => 'CommodityActivityController@store']); // 新增
                $api->get('/', ['uses' => 'CommodityActivityController@list']); // 新增
                $api->delete('/{id}', ['uses' => 'CommodityActivityController@delete']); // 删除
                $api->patch('/{id}', ['uses' => 'CommodityActivityController@update']); // 编辑
                $api->patch('/{id}/status', ['uses' => 'CommodityActivityController@updateStatus']); // 上下架
                $api->patch('/{id}/locking', ['uses' => 'CommodityActivityController@updateLocking']); // 锁定/激活
                $api->patch('/{id}/material-settings', ['uses' => 'CommodityActivityController@materialSetting']); // 素材设置编辑
                $api->patch('/{id}/moments-settings', ['uses' => 'CommodityActivityController@momentsSetting']); // 朋友圈素材设置编辑
                $api->get('/{id}/stocking-export', ['uses' => 'CommodityActivityController@stockingExport']); // 导出备货单
                $api->get('/{id}/invoice-export', ['uses' => 'CommodityActivityController@invoiceExport']); // 导出发货单
                $api->patch('/sku/{id}', ['uses' => 'CommodityActivityController@updateSku']); // 编辑 SKU 信息
            });

            // 好评返团 (和上面接口除了地址不一样, 其余一样, 是为了权限的区分)
            // 2020-10-15 02:28:24 暂时接口的权限去掉了
            $api->group(['prefix' => 'praise-return'], function () use ($api) {
                $api->get('/{id}', ['uses' => 'CommodityActivityController@info']); // 详情
                $api->post('/', ['uses' => 'CommodityActivityController@store']); // 新增
                $api->get('/', ['uses' => 'CommodityActivityController@list']); // 列表
                $api->delete('/{id}', ['uses' => 'CommodityActivityController@delete']); // 删除
                $api->patch('/{id}', ['uses' => 'CommodityActivityController@update']); // 编辑
                $api->patch('/{id}/status', ['uses' => 'CommodityActivityController@updateStatus']); // 上下架
                $api->patch('/{id}/locking', ['uses' => 'CommodityActivityController@updateLocking']); // 锁定/激活
                $api->patch('/{id}/material-settings', ['uses' => 'CommodityActivityController@materialSetting']); // 素材设置编辑
                $api->patch('/{id}/moments-settings', ['uses' => 'CommodityActivityController@momentsSetting']); // 朋友圈素材设置编辑
                $api->get('/{id}/stocking-export', ['uses' => 'CommodityActivityController@stockingExport']); // 导出备货单
                $api->get('/{id}/invoice-export', ['uses' => 'CommodityActivityController@invoiceExport']); // 导出发货单
                $api->patch('/sku/{id}', ['uses' => 'CommodityActivityController@updateSku']); // 编辑 SKU 信息
            });

            // 标签
            $api->group(['prefix' => 'labels'], function () use ($api) {
                $api->post('/', ['uses' => 'CommodityLabelController@store']); // 新增
                $api->get('/', ['uses' => 'CommodityLabelController@list']); // 列表
                $api->delete('/{id}', ['uses' => 'CommodityLabelController@delete']); // 删除
                $api->patch('/{id}', ['uses' => 'CommodityLabelController@update']); // 编辑
            });

            $api->group([], function () use ($api) {
                $api->get('/', ['uses' => 'CommodityController@list']); // 列表
                $api->get('/{id}', ['uses' => 'CommodityController@info']); // 详情
                $api->post('/', ['uses' => 'CommodityController@store']); // 新增
                $api->delete('/{id}', ['uses' => 'CommodityController@delete']); // 删除
                $api->patch('/{id}', ['uses' => 'CommodityController@update']); // 编辑
            });
        });

        // 代理商
        $api->group(['prefix' => 'agents'], function () use ($api) {
            // 标签
            $api->group(['prefix' => 'labels'], function () use ($api) {
                $api->post('/', ['uses' => 'AgentLabelController@store']); // 新增
                $api->get('/', ['uses' => 'AgentLabelController@list']); // 列表
                $api->delete('/{id}', ['uses' => 'AgentLabelController@delete']); // 删除
                $api->patch('/{id}', ['uses' => 'AgentLabelController@update']); // 编辑
            });

            // 奖励设置
            $api->group(['prefix' => 'reward-setting'], function () use ($api) {
                $api->get('/table', ['uses' => 'RewardSettingsController@table']); // 奖励规则几张表数据
                $api->patch('/table/{id}', ['uses' => 'RewardSettingsController@edit']); // 编辑规则
            });

            $api->group([], function () use ($api) {
                $api->patch('/balance', ['uses' => 'AgentController@adjustBalance']); // 变更代理商余额
                $api->post('/', ['uses' => 'AgentController@store']); // 新增
                $api->get('/team', ['uses' => 'AgentController@teamList']); // 直接/间接邀请的用户
                $api->get('/', ['uses' => 'AgentController@list']); // 列表
                $api->get('/running-bill', ['uses' => 'AgentController@runningBill']); // 流水明细
                $api->patch('/change-belonging', ['uses' => 'AgentController@changeBelonging']); // 变更
                $api->get('/{id}', ['uses' => 'AgentController@info']); // 详情
                $api->patch('/{id}', ['uses' => 'AgentController@update']); // 编辑
                $api->patch('/{id}/direct-inviter', ['uses' => 'AgentController@changeBelonging']); // 调整代理直接邀请人和所属合伙人, 以及代理下级的间接邀请人和所属合伙人
                $api->patch('/{id}/status', ['uses' => 'AgentController@updateStatus']); // 启用禁用
            });
        });

        // 订单
        $api->group(['prefix' => 'orders'], function () use ($api) {
            $api->group(['prefix' => 'after-sale'], function () use ($api) {
                $api->get('/', ['uses' => 'AfterSaleOrderController@list']); // 售后订单列表
                $api->get('/{id}', ['uses' => 'AfterSaleOrderController@info']); // 售后订单详情
                $api->post('/audit/{id}', ['uses' => 'AfterSaleOrderController@audit']); // 审核售后订单
            });

            $api->group([], function () use ($api) {
                $api->get('/', ['uses' => 'OrderController@list']); // 订单列表
                $api->patch('/express-delivery', ['uses' => 'OrderController@expressDelivery']); // 订单快递
                $api->patch('/remark', ['uses' => 'OrderController@remark']); // 订单备注
                $api->get('/{id}', ['uses' => 'OrderController@info']); // 订单详情
                $api->patch('/{id}/receiving-information', ['uses' => 'OrderController@updateReceivingInformation']); // 修改订单收件信息
                $api->delete('/{numbering}', ['uses' => 'OrderController@cancelByNumbering']); // 根据订单号 取消订单
            });
        });

        // 财务
        $api->group(['prefix' => 'finance'], function () use ($api) {
            $api->group(['prefix' => 'statistics'], function () use ($api) {
                $api->get('/profit', ['uses' => 'FinanceController@profitStatistics']); // 商品利润统计
                $api->get('/daily-report', ['uses' => 'FinanceController@dailyReportStatistics']); // 每日报表

                $api->group([], function () use ($api) {
                    $api->get('/daily-reward', ['uses' => 'FinanceController@dailyRewardList']); // 每日活动奖励 列表
                    $api->post('/daily-reward', ['uses' => 'FinanceController@approvalOfDailyAwards']); // 审核每日活动奖励
                });

                $api->group([], function () use ($api) {
                    $api->get('/monthly-reward', ['uses' => 'FinanceController@monthlyRewardList']); // 每月活动奖励 列表
                    $api->post('/monthly-reward', ['uses' => 'FinanceController@approvalOfMonthlyAwards']); // 审核每月活动奖励
                });

                $api->get('/cultivation-award', ['uses' => 'FinanceController@getCultivationAward']); // 培养奖
                $api->get('/after-sale-compensation', ['uses' => 'FinanceController@getAfterSaleCompensation']); // 售后补偿
            });

            $api->group([], function () use ($api) {
                $api->get('/withdrawals-record', ['uses' => 'AgentController@withdrawalsRecord']); // 提现记录
                $api->post('/withdrawals-record/approve', 'AgentController@approveWithdrawals'); // 审批提现
            });

            $api->get('/financial-details', ['uses' => 'FinanceController@financialDetails']); // 财务明细
        });
    });
});
